package com.wx.JerseySpring.action;

import com.wx.JerseySpring.entity.User;
import com.wx.JerseySpring.service.UserService;
import net.sf.json.JSONObject;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * Created by Administrator on 2016/11/16.
 */
@Component
@Path("/user")
@Scope("prototype")
public class UserAction {

    @Resource
    private UserService userService;

    @GET
    @Path("/list")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public String getAllUser(){
        List<User> users = userService.getAllUser();
        StringBuffer result = new StringBuffer("");
//        for(User u:users){
//            result.append(u.toString()+"/n");
//        }
        JSONObject jsonObject = JSONObject.fromObject(users.get(0));
        return jsonObject.toString();
    }
}
